<?php
namespace Admin\Controller;
//use Think\Controller;
use Tools\AdminController;
class FrontController extends AdminController {

//    首页轮播图列表展示
    public function showlist(){
        $picture = D('picture')->select();
        $this->assign('pic',$picture);
        $this->display();
    }
    public function add(){
        if(!IS_POST){
			$this->display();
		}else{
			$frontModel = D('picture');

			//图片上传以及缩略图
	    	$thumb = new \Think\Image();			
			$upload = new \Think\Upload();
			$upload->exts = array('jpg','gif','png','jpeg');//设置图片上传类型
			$upload->rootPath = './Public/up/';//设置上传根目录
			$info = $upload->upload();
			// print_r($info);
			// exit();
	    		if(!$info){
	    			var_dump($upload->getError());
	    		}else{
	    		$_POST['p_img'] = 'Public/up/'.$info['p_img']['savepath'].$info['p_img']['savename'];
	    		$thumb->open($_POST['p_img']);
	    		$thumb_path = 'Public/up/thumb/'.$info['p_img']['savename'];
	    		$thumb->thumb(230,230)->save($thumb_path);
	    		$_POST['thumb_img'] = '/'.$thumb_path;
	    		$_POST['add_time'] = time();	
			$front = $frontModel->add($_POST);
				if($front){
					$this->redirect('showlist');
				}else{
					$this->error('添加失败');
				}
			}
		}
    } 
    
}
